/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.resource.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.common.utils.IdGen;
import com.lczyfz.istep.modules.resource.dao.ResourceCtfSubjectDao;
import com.lczyfz.istep.modules.resource.entity.ResourceCtfSubject;
import com.lczyfz.istep.modules.sys.entity.User;
import com.lczyfz.istep.modules.sys.service.SystemService;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import com.lczyfz.istep.modules.teach.entity.TeachStudentCtfsubject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * CTF题目管理Service
 * @author dh
 * @version 2017-01-16
 */
@Service
@Transactional(readOnly = true)
public class ResourceCtfSubjectService extends CrudService<ResourceCtfSubjectDao, ResourceCtfSubject> {

	@Autowired
	ResourceCtfSubjectDao resourceCtfSubjectDao;
	@Autowired
	private SystemService systemService;

	public ResourceCtfSubject get(String id) {
		return super.get(id);
	}
	
	public List<ResourceCtfSubject> findList(ResourceCtfSubject resourceCtfSubject) {
		return super.findList(resourceCtfSubject);
	}
	
	public Page<ResourceCtfSubject> findPage(Page<ResourceCtfSubject> page, ResourceCtfSubject resourceCtfSubject) {
		return super.findPage(page, resourceCtfSubject);
	}

	public Page<ResourceCtfSubject> findPageByCtfSetId(Page<ResourceCtfSubject> page, ResourceCtfSubject resourceCtfSubject) {
		resourceCtfSubject.setPage(page);
		page.setList(dao.findListByCtfSetId(resourceCtfSubject));
		return page;
	}


	@Transactional(readOnly = false)
	public void save(ResourceCtfSubject resourceCtfSubject) {
		super.save(resourceCtfSubject);
	}
	
	@Transactional(readOnly = false)
  	public void delete(ResourceCtfSubject resourceCtfSubject) {
		super.delete(resourceCtfSubject);
	}

	//CTF题目集链接查看题目
	public Page<ResourceCtfSubject> viewCtfSubjectList(Page<ResourceCtfSubject> page, ResourceCtfSubject resourceCtfSubject) {
		logger.debug("==Evan==viewCtfSubjectList=="+resourceCtfSubject.getCtfSetId());
		resourceCtfSubject.setPage(page);
		page.setList(dao.viewCtfSubjectList(resourceCtfSubject));
		return page;
	}
//fds
	//我的CTF题目集-进入题目集
	public Page<ResourceCtfSubject> stuEnterCtfSetList(Page<ResourceCtfSubject> page, ResourceCtfSubject resourceCtfSubject) {
		resourceCtfSubject.setPage(page);
		page.setList(resourceCtfSubjectDao.stuEnterCtfSetList(resourceCtfSubject));
		return page;
	}
	@Transactional(readOnly = false)
	public void saveAnswer(TeachStudentCtfsubject teachStudentCtfsubject)
	{
		String id=IdGen.uuid();
		User user = UserUtils.getUser();
		teachStudentCtfsubject.setId(id);
		teachStudentCtfsubject.setUserId(user.getId());
		teachStudentCtfsubject.setUpdateBy(user);
		teachStudentCtfsubject.setCreateBy(user);

		Date date=new Date();
		teachStudentCtfsubject.setUpdateDate(date);
		teachStudentCtfsubject.setCreateDate(date);

		dao.saveAnswer(teachStudentCtfsubject);
	}
	@Transactional(readOnly = false)
	public void updateAnswer(TeachStudentCtfsubject teachStudentCtfsubject){
		dao.updateAnswer(teachStudentCtfsubject);
	}
	public TeachStudentCtfsubject findStudentCtfSubject(TeachStudentCtfsubject teachStudentCtfsubject){
		return dao.findStudentCtfSubject(teachStudentCtfsubject);
	}
	public ResourceCtfSubject findCtfSubjectByName(ResourceCtfSubject resourceCtfSubject)
	{
		return dao.findCtfSubjectByName(resourceCtfSubject);
	}


}